package homework_java.eg;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Iterator;
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
class Employee implements Comparable{
	public String id,name,date, phone;
	public Employee() {}
	public Employee(String id) {this.id = id;}
	public Employee(String id, String na, String da, String phone) {
		this.id = id; this.name = na; this.date = da; this.phone = phone;
	}
	public String toString() {
return "[id = "+id+", name="+name+", date="+date+", phone="+phone+"]";
	}
	public boolean equals(Object obj) {
		Employee p = (Employee)obj;
		return new EqualsBuilder().append(this.id, p.id).isEquals();
	}
	public int hashCode() {
		return new HashCodeBuilder().append(this.id).toHashCode();
		
	}
	public int compareTo(Object o) {
		return ((Employee)o).id.compareTo(this.id);
	}
}
class Store{
	public ArrayList<Employee> EmployeeList = new ArrayList<Employee>();
	public boolean addEmployee(Employee o) {
		if(EmployeeList.contains(o))
			return false;
		EmployeeList.add(o);
		return true;
	}
	public void removeEmployee(Employee o) {
		if(EmployeeList.contains(o))
			EmployeeList.remove(o);
	}
	public void display() {
		for(Iterator<Employee> it = EmployeeList.iterator(); it.hasNext();)
			System.out.println(it.next());
	}
}
class DateComparator implements Comparator<Employee>{
	public int compare(Employee o1, Employee o2) {
		return o1.date.compareTo(o2.date);
	}	
}
class Test {
	public static void main(String[] args) {
	Store s = new Store();
	s.addEmployee(new Employee("001", "Ann","20180120", "13011111111"));
	s.addEmployee(new Employee("001", "Jack","20160220", "13911119919"));
	s.addEmployee(new Employee("002", "Anna","20170118", "15688888888"));
		s.display();
		Collections.sort(s.EmployeeList, new DateComparator());
		s.display();
		s.removeEmployee(new Employee("001"));
		s.removeEmployee(new Employee("000"));
		s.display();		
	}
}